<?php

require_once("../../simpletest/autorun.php");
require_once("../../simpletest/unit_tester.php");
//require_once '../../data/IRepository.php';
require_once ('../../data.impl/Repository.php');
//include '../../paramcsts/Param.php';

spl_autoload_register('testAutoload');

function testAutoload($classname){
	include __DIR__ .'/data.model/'.$classname.'php';

		
}


	class TestRepository extends UnitTestCase{
		
		private $connexion;
		private $userRepoId;
		
		public function setUp(){
			$connectionParameter = array(
					'engine' => 'mysql',
					'host' => 'localhost',
					'user' => 'root',
					'password' => '' ,
					'dbname' =>'applicationn_sotd'
			);
			$this->userRepoId = "1-M001";
			$dsn = $connectionParameter['engine'] . 
				":dbname=" .$connectionParameter['dbname'] . 
				";host=". $connectionParameter['host'];
			try {
			$this->connexion = new PDO($dsn,$connectionParameter['user'],$connectionParameter['password']);
			}
			catch(PDOException $e){
				echo $e->getMessage();
				exit;
			}
			
		}				
		
		public function testGetObject(){	
			$sql ="select * from sotd_user where uid='".$this->userRepoId . "'" ;
			echo $sql ." <br />";
			try {
				$dbh = $this->connexion;
				$pdoStatement = $dbh->query($sql);
				//echo gettype($this->connexion);
				//echo gettype($pdoStatement);
				//$this->connexion->closeCursor();
				$login = "";
				$uid ="";
				$password = "";
				
				
				foreach($pdoStatement as $row){
					$login = $row['login'];
					$uid = $row['uid'];
					$password = $row['password'];	
					
				}
				
				$this->assertEqual($login,"davidesr");	
				$this->assertEqual($uid,"1-M001");
				$this->assertEqual($password,"davidesr");
			}
			catch(PDOException $e){
				echo $e->getMessage();
			}			
			
		}
		
		public function testInsertObject() {
			return $this->assertTrue(true);
		}
		
		public function testDeleteObject() {
			return $this->assertTrue(true);
		}
		
		public function testUpdateObject(){
			return $this->assertTrue(true);
		}
		
	}

?>